package com.baidu.threadSafe;

public class Account {
    private String id;
    private double money;

    public synchronized void drawMoney(double money){
        //1.查看取钱的线程名称
        String name = Thread.currentThread().getName();

        //2.判断余额是否够
        if(this.money >= money){
            //2.1.够就取钱
            System.out.println(name + "取钱成功" + money);
            //2.2.修改账户余额
            this.money -= money;
        }else {
            System.out.println("余额不足");
        }

        //3.输出余额
        System.out.println("当前余额为" + this.money);
    }

    public Account() {
    }

    public Account(String id, double money) {
        this.id = id;
        this.money = money;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }
}
